﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.Design;
using Newtonsoft.Json.Linq;
using ProjectN.Core.Element.Def;

namespace ProjectN.Core.Fore.Editor
{
    class ImageInfo_EditorDEF : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context)
            => UITypeEditorEditStyle.DropDown;

        public override bool IsDropDownResizable => true;
        public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value)
        {
            if (value is not ImageInfo info)
                return value;

            if (provider.GetService(typeof(IWindowsFormsEditorService)) is not IWindowsFormsEditorService editorService)
                return value;

            var control = new ImageInfo_EditorControl { Info = info };
            editorService.DropDownControl(control);
            return control.Info;
        }
        public override bool GetPaintValueSupported(ITypeDescriptorContext? context)
            => true;

        public override void PaintValue(PaintValueEventArgs e)
        {
            if (e.Value is not ImageInfo info)
                return;

            Graphics gr = e.Graphics;
            Rectangle rect = e.Bounds;
            Image image = info.Create();

            gr.DrawImage(image, rect);
        }
    }
}
